package com.yanqu.road.server.pb;

import com.yanqu.road.entity.drugstore.*;
import com.yanqu.road.pb.drugstore.DrugStoreProto;

import java.util.List;

public class DrugStorePb {

    public static DrugStoreProto.DrugLandTemp.Builder buildDrugLandTemp(UserDrugLandData landData){
        DrugStoreProto.DrugLandTemp.Builder builder = DrugStoreProto.DrugLandTemp.newBuilder();
        builder.setDrugId(landData.getDrugId());
        builder.setEndTime(landData.getMatureTime());
        builder.setLandId(landData.getLandId());
        builder.setNum(1);
        builder.setStartTime(landData.getPlantTime());
        builder.setPlantId(landData.getPlanId());
        return builder;
    }

    public static DrugStoreProto.DrugStoreTemp.Builder buildDrugStoreTemp(UserDrugStoreData drugStoreData) {
        DrugStoreProto.DrugStoreTemp.Builder builder = DrugStoreProto.DrugStoreTemp.newBuilder();
        builder.setLv(drugStoreData.getDrugStoreLv());
        builder.setUnLockAuto(drugStoreData.getBookKeeperLv() > 0);
        builder.setPower(drugStoreData.getPower());
        builder.setLastRecoverPowerTime(drugStoreData.getLastRecoverPowerTime());
        for (int i = 0; i < drugStoreData.getNpcQueueList().size(); i++) {
            DrugStoreQueue queue = drugStoreData.getNpcQueueList().get(i);
            DrugStoreProto.DrugStoreQueueNpcTemp.Builder npcBuilder = buildDrugStoreQueueTemp(queue);
            builder.addWaitNpc(npcBuilder);
        }
        builder.setTableNum(drugStoreData.getDoctorTableList().size());
        builder.setExperience(drugStoreData.getExperience());
        builder.setTongBi(drugStoreData.getTongBi());
        builder.setLandNum(drugStoreData.getLandNum());
        builder.setReceiveNum(drugStoreData.getReceiveNum());
        List<DrugOrderReward> rewardList = drugStoreData.getRewardList();
        for (int i = 0; i < rewardList.size(); i++) {
            DrugOrderReward reward = rewardList.get(i);
            DrugStoreProto.DrugTreasureBowlRewardTemp.Builder rewardBuild = buildTreasureBowlReward(reward);
            builder.addBowlReward(rewardBuild);
        }
        builder.addAllUnlockDrug(drugStoreData.getUnLockDrug());
        builder.setBuffValue(drugStoreData.getBuffValue().getBuffValue());
        builder.setBuffEndTime(drugStoreData.getBuffValue().getEndTime());
        for (DrugStoreTeach tech : drugStoreData.getTechList()) {
            DrugStoreProto.DrugTechnologyTemp.Builder techBuilder = buildTech(tech);
            builder.addTech(techBuilder);
        }
        builder.setEnterTime(drugStoreData.getEntryViewTime());
        return builder;
    }

    public static DrugStoreProto.DrugTechnologyTemp.Builder buildTech(DrugStoreTeach tech) {
        DrugStoreProto.DrugTechnologyTemp.Builder techBuilder = DrugStoreProto.DrugTechnologyTemp.newBuilder();
        techBuilder.setTech(tech.getId());
        techBuilder.setLv(tech.getLv());
        return techBuilder;
    }

    public static DrugStoreProto.DrugTreasureBowlRewardTemp.Builder buildTreasureBowlReward(DrugOrderReward reward) {
        DrugStoreProto.DrugTreasureBowlRewardTemp.Builder rewardBuild = DrugStoreProto.DrugTreasureBowlRewardTemp.newBuilder();
        rewardBuild.setChuFang(reward.getCf());
        rewardBuild.setLv(reward.getLv());
        rewardBuild.setExperience(reward.getExp());
        rewardBuild.setTongBi(reward.getTb());
        rewardBuild.setShuLianDu(reward.getSld());
        return rewardBuild;
    }

    public static DrugStoreProto.DrugStoreQueueNpcTemp.Builder buildDrugStoreQueueTemp(DrugStoreQueue queue) {
        DrugStoreProto.DrugStoreQueueNpcTemp.Builder npcBuilder = DrugStoreProto.DrugStoreQueueNpcTemp.newBuilder();
        npcBuilder.setId(queue.getqId());
        npcBuilder.setChuFang(queue.getCf());
        npcBuilder.setDialogId(queue.getdId());
        return npcBuilder;
    }

    public static DrugStoreProto.DrugOrderTemp.Builder builderDrugOrderTemp(UserDrugChuFangOrderData orderData){
        DrugStoreProto.DrugOrderTemp.Builder builder = DrugStoreProto.DrugOrderTemp.newBuilder();
        builder.setNo(orderData.getNo());
        builder.setNpcId(orderData.getNpc());
        builder.setTable(orderData.getTable());
        builder.setChuFang(orderData.getChuFang());
        builder.setDialogId(orderData.getDialogId());
        //订单药材需求
        for (DrugOrderNeed process : orderData.getProcess()) {
            DrugStoreProto.DrugOrderDrugNeedTemp.Builder needBuilder = DrugStoreProto.DrugOrderDrugNeedTemp.newBuilder();
            needBuilder.setItemId(process.getItemId());
            needBuilder.setBagNum(process.getBagNum());
            needBuilder.setPlanNum(process.getPlanNum());
            needBuilder.setNeedNum(process.getNeedNum());
            needBuilder.setDeduct(process.isDeduct());
            builder.addDrug(needBuilder);
        }
        builder.setOrderTime(orderData.getOrderTime());
        builder.setDrugPlantStartTime(orderData.getDrugPlantStartTime());
        builder.setDrugPlantDoneTime(orderData.getDrugPlantDoneTime());
        builder.setDrugMakeEndTime(orderData.getDrugMakeEndTime());
        builder.setFinishTime(orderData.getFinishTime());
        builder.setGetRewardTime(orderData.getGetRewardTime());
        builder.setStatus(orderData.getState());
        return builder;
    }

    public static DrugStoreProto.DrugChuFangTemp.Builder buildDrugChuFangTemp(UserDrugChuFangData data) {
        DrugStoreProto.DrugChuFangTemp.Builder builder = DrugStoreProto.DrugChuFangTemp.newBuilder();
        builder.setChuFang(data.getChuFang());
        builder.setLv(data.getLv());
        builder.setShuLianDu(data.getShuLianDu());
        return builder;
    }
}
